<?php
/* Recent Trackbacks plugin for Textcube 1.5
   ----------------------------------
   Version 1.0
   Tatter and Friends development team.

   Creator          : NANI
   Maintainer       : Peris, inureyes, graphittie

   Created at       : 2006.10.10
   Last modified at : 2007.8.10

 This plugin shows recent trackback on 'quilt'.
 For the detail, visit http://forum.Textcube.com/ko


 General Public License
 http://www.gnu.org/licenses/gpl.html

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

*/

// lib/model/trackback.php : 46 line
function _getRecentTrackbacks($blogid) {
	global $database;
	global $skinSetting;
	$trackbacks = array();
	$sql = doesHaveOwnership() ? "SELECT * 
		FROM 
			{$database['prefix']}Trackbacks 
		WHERE 
			blogid = $blogid AND isFiltered = 0 
		ORDER BY 
			written 
		DESC LIMIT 
			{$skinSetting['trackbacksOnRecent']}" : 
		"SELECT t.* 
		FROM 
			{$database['prefix']}Trackbacks t 
			LEFT JOIN {$database['prefix']}Entries e ON t.blogid = e.blogid AND t.entry = e.id
			LEFT JOIN {$database['prefix']}Categories c ON e.blogid = c.blogid AND e.category = c.id
		WHERE 
			t.blogid = $blogid AND e.draft = 0 AND e.visibility >= 2 AND (c.visibility > 1 OR e.category = 0) AND t.isFiltered = 0 
		ORDER BY 
			t.written 
		DESC LIMIT 
			{$skinSetting['trackbacksOnRecent']}";
	if ($result = DBQuery::query($sql)) {
		while ($trackback = mysql_fetch_array($result))
			array_push($trackbacks, $trackback);
	}
	return $trackbacks;
}

function CT_RecentTB_Default($target) {
	global $blogid;
	requireComponent("Eolin.PHP.Core");
	requireComponent("Textcube.Function.misc");
	
	$target .= '<ul>';
	$trackbacks = _getRecentTrackbacks($blogid);
	foreach ($trackbacks as $trackback) {
		$target .= '<li>';
		$target .= '<span style="color: #9E7C54;">'.Timestamp::format2($trackback['written']).'</span>';
		$target .= '<a href="'.$blogURL.'/'.$trackback['entry'].'#trackback'.$trackback['id'].'"> ';
		$target .= htmlspecialchars(UTF8::lessenAsEm($trackback['subject'],30));
		$target .= '</a> - ';
		$target .= '<cite style="color: #777; font-style: normal;">';
		$target .= htmlspecialchars(UTF8::lessenAsEm($trackback['site'], 10));
		$target .= '</cite>';
		$target .= '</li>';
	}
	$target .= '</ul>';

	return $target;
}
?>
